/*-------**********
Company Name: Elixir Web Solution
Programmer Name: Rupinder Singh Bedi
Created On:4 Feb,2004
Description: Text Editor File
********--------------*/
function OpenNewWindow(w,h,mypage,newwinanme)
  	{
	  	if (HTMLMode[1]) { return; }
	  	var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no';
		imgwin = window.open(mypage, newwinanme, winprops);
		if (parseInt(navigator.appVersion) >= 4) {imgwin.window.focus();}
 	}
function OpenNewWindowwithscroll(w,h,mypage,newwinanme)
  	{
	  	if (HTMLMode[1]) { return; }
	  	var winl = (screen.width - w) / 2;
		var wint = 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no';
		imgwin = window.open(mypage, newwinanme, winprops);
		if (parseInt(navigator.appVersion) >= 4) {imgwin.window.focus();}
 	}

//-------**********trim function **************--------------------
function LTrim(str)
{
	for (var i=0; str.charAt(i)==" "; i++);
	return str.substring(i,str.length);
 }
function RTrim(str)
 {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
 }
 function Trim(str)
 {
	return LTrim(RTrim(str));
 }

 //*********-----------Font Selection------------****************8
function fontSelection(thefontface,thefontsize,thefontstyle,thefontcolor,fontunderline)
	{
		format('fontname',thefontface);
		format('fontsize',thefontsize);
		if (thefontstyle=="bold")
		{
		format('bold');
		}
		if (thefontstyle=="italic")
		{
		format('italic');
		}
		if (thefontstyle=="bolditalic")
		{
		format('bold');	
		format('italic');
		}
		if (thefontcolor!="")
		{
		format('forecolor', thefontcolor);
		}
		if (fontunderline=="yes")
		{
		format('underline');
		}
	}

//---------********create table**************------------------
function crTable(rows,cols,border,bordercolor,width,height,color,cellpadd,cellspace,align,imageurl)
{
 	strtable="<table border="+border+" align="+align+" bgcolor="+color;
	if (border!="0")
	{
		if (bordercolor!="")
		{
			strtable=strtable+" bordercolor="+bordercolor;
		}
	}
	if (width!="")
	{
	strtable=strtable+" width="+width;
	}
	if (height!="")
	{
	strtable=strtable+" height="+height;
	}
	if (imageurl!="")
	{
	strtable=strtable+" background="+imageurl;
	}
	strtable=strtable+" cellpadding="+cellpadd;
	strtable=strtable+" cellspacing="+cellspace;
	strtable=strtable+">";
	for (j=1;j<=rows;j++)
	{
		strtable=strtable+"<tr>";
		for (k=1;k<=cols;k++)
		{
			strtable=strtable+"<td></td>";
		}
		strtable=strtable+"</tr>";
	}
	strtable=strtable+"</table>";
	insertIntoIframe(strtable)
}

//---------*********insert image**************-------------
function insertimg(imgsrc,border,width,height,vspace,hspace,alttag,imgalign)
{
	strimgtag="<img src=\""+imgsrc+"\" border="+border;
	if(width!="")
	{
		strimgtag+=" width="+width;
	}
	if(height!="")
	{
		strimgtag+=" height="+height;
	}
	if(vspace!="")
	{
		strimgtag+=" vspace="+vspace;
	}
	if(hspace!="")
	{
		strimgtag+=" hspace="+hspace;
	}
	if(alttag!="")
	{
		strimgtag+=" alt=\""+alttag+"\"";
	}
	if(imgalign!="")
	{
		strimgtag+=" align="+imgalign;
	}
	strimgtag+=" >";
	insertIntoIframe(strimgtag);
}
//--------***************create Hyperlink***************--------------
function createHyperlink(href,target,caption)
{
	hreflink="<A HREF=\""+href+"\" target=\""+target+"\">"+caption+"</A>";
	insertIntoIframe(hreflink);
}

//Finds and returns an element.
function getEl(sTag,start) {
  while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
  return start;
}

//*****************insert text*********************************
function insertText(tagStart,tagEnd)
	{
		if (!validateMode()) return;
		var sel=Composition.document.selection.createRange();
		htmltext=sel.htmlText;
		if (htmltext=="")
		{
		alert("Please select Text");
		Composition.focus();
		}
		else
		{
		strtext=tagStart+htmltext+tagEnd;
		insertIntoIframe(strtext)
		}
	}
	
	//-----------********** insert into IFRAME************------------
function insertIntoIframe(strHTML)
{
 var sel=DHTMLSafe.DOM.selection.createRange();
 sel.pasteHTML(strHTML);
 sel.select();
DHTMLSafe.focus();
}

function editorhelp()
{
	if (HTMLMode[1]) { return; }
	OpenNewWindowwithscroll('350','400','../CodeLibrary/texteditor/editorhelp.htm','helpwin');
}

function specialchars()
{
	if (HTMLMode[1]) { return; }
	OpenNewWindowwithscroll('390','260','../CodeLibrary/texteditor/specialchars.htm','specialchars');
}

function insertimage()
{
	if (HTMLMode[1]) { return; }
	OpenNewWindowwithscroll('490','420','../CodeLibrary/texteditor/insertimage.php','insertimage');
}
function insertimage1()
{
	if (HTMLMode[1]) { return; }
	OpenNewWindowwithscroll('490','420','../CodeLibrary/texteditor/insertimage1.php','insertimage');
}
//------------open hyperlink window-----------------
function OpenHyperlinkWindow()
{
 if (HTMLMode[1]) { return; }
 if (DHTMLSafe.DOM.selection.type=="None")
 {	
  var mypage = '../CodeLibrary/texteditor/editor_hyperlink_withcaption.htm';
 }
 else
 {
   var mypage = '../CodeLibrary/texteditor/editor_hyperlink_withoutcaption.htm';
 }
   OpenNewWindow('400','165',mypage,'hyperlinkwindow');
 }
 
function inserttable()
{
	if (HTMLMode[1]) { return; }
	OpenNewWindowwithscroll('520','370','../CodeLibrary/texteditor/createtable.htm','createtable');
}

function insertrow()
{
	DHTMLSafe.ExecCommand(DECMD_INSERTROW,OLECMDEXECOPT_DODEFAULT);
	DHTMLSafe.focus();
}

 function deleterow()
{
	DHTMLSafe.ExecCommand(DECMD_DELETEROWS,OLECMDEXECOPT_DODEFAULT);
	DHTMLSafe.focus();
}

 function insertcols()
{
	DHTMLSafe.ExecCommand(DECMD_INSERTCOL,OLECMDEXECOPT_DODEFAULT);
	DHTMLSafe.focus();
}

 function deletecols()
{
	DHTMLSafe.ExecCommand(DECMD_DELETECOLS,OLECMDEXECOPT_DODEFAULT);
	DHTMLSafe.focus();
}

//---------*********insert Button**************-------------
function crSubmit(tname,tvalue,twidth,tonclick)
{
	str="<input type=submit name="+tname+" value='"+tvalue+"'";
	if (twidth!="")
	{
	str=str+" style='width:"+twidth+"'";
	} 
	if (tonclick!="")
	{
	str=str+" OnClick='"+tonclick+"'";
	}
	str=str+">";
	insertIntoIframe(str)
}
//---------*********insert Button**************-------------
function crForm(tname,taction,enctype,tmethod,tonsubmit)
{
	str="<form name="+tname+" action='"+taction+"' Method="+tmethod;
	if (enctype!="default")
	{
	str=str+" enctype='"+enctype+"'";
	} 
	if (tonsubmit!="")
	{
	str=str+" OnSubmit='"+tonsubmit+"'";
	}
	str=str+">&nbsp;&nbsp;&nbsp;</form>";
	insertIntoIframe(str)
}
//---------*********insert Reset Button**************-------------
function crReset(tname,tvalue,twidth)
{
	str="<input type=reset name="+tname+" value='"+tvalue+"'";
	if (twidth!="")
	{
	str=str+" style='width:"+twidth+"'";
	} 
	str=str+">";
	insertIntoIframe(str)
}
//---------*********insert select box**************-------------
function crDropDown(selectedval)
{
	insertIntoIframe(selectedval);
}
function crButton(tname,tvalue,twidth,tonclick)
{
	str="<input type=button name="+tname+" value='"+tvalue+"'";
	if (twidth!="")
	{
	str=str+" style='width:"+twidth+"'";
	} 
	if (tonclick!="")
	{
	str=str+" OnClick='"+tonclick+"'";
	}
	str=str+">";
	insertIntoIframe(str)
}

function crTextField(tname,tvalue,tsize,tmax)
{
	if (tmax=="")
	{
	str="<input type=text name="+tname+" size="+tsize+" value='"+tvalue+"' maxlength="+tmax+">"; 
	}
	else
	{
	str="<input type=text name="+tname+" size="+tsize+" value='"+tvalue+"'>"; 
	}
	insertIntoIframe(str)
}

//---------*********insert hidden field**************-------------
function crHiddenField(tname,tvalue)
{
	str="<input type=hidden name="+tname+" value='"+tvalue+"'>"; 
	insertIntoIframe(str)
}

//---------*********insert Textarea**************-------------
function crTextarea(tname,tvalue,trows,tcols)
{
	str="<textarea name="+tname+" cols="+tcols+" rows="+trows+">"+tvalue+"</textarea>"; 
	insertIntoIframe(str);
}
//Finds and returns an element.
function getEl(sTag,start) {
  while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
  return start;
}

//---------*********insert check box**************-------------
function crCheckbox(tname,tvalue,tchecked)
{
	if (tchecked=="yes")
	{
	str="<input type=checkbox name="+tname+" value="+tvalue+" checked>";
	}
	else
	{
	str="<input type=checkbox name="+tname+" value="+tvalue+">";
	}
	insertIntoIframe(str)
}
//---------*********insert check box**************-------------
function crRadio(tname,tvalue,tchecked)
{
	if (tchecked=="yes")
	{
	str="<input type=radio name="+tname+" value="+tvalue+" checked>";
	}
	else
	{
	str="<input type=radio name="+tname+" value="+tvalue+">";
	}
	insertIntoIframe(str)
}

function alignjustify()
{
	if (HTMLMode[1]) { return; }
	if (DHTMLSafe.DOM.selection.type=="None")
	{	
	 alert("please select the text to justify");
	 DHTMLSafe.focus();
	}
	else
	{
	   var sel=DHTMLSafe.DOM.selection.createRange();
	   cap=sel.htmlText;
	   var alignedtext ='<div align="justify">'+cap+'</div>';
	   insertIntoIframe(alignedtext);
	}
}